perf(skl): embed Iterator by value in UniIterator#2288
Open
shaunpatterson wants to merge 1 commit into
Open
Conversation
Halves the per-memtable iterator construction allocation count by embedding the inner Iterator inside UniIterator instead of holding a *Iterator. Previously NewUniIterator allocated twice: once for the inner Iterator (via NewIterator) and once for the UniIterator wrapper. Embedding by value collapses these into a single heap allocation. Extracts the shared (*Iterator).init helper so future setup added in NewIterator applies uniformly to UniIterator's embedded construction path. Saves 1 alloc and 9 B per UniIterator construction on BenchmarkRollupKeyIterator: before: 826 B/op, 16 allocs/op after: 817 B/op, 15 allocs/op In dgraph's posting list rollup, ~6 of these are constructed per cache miss (1 mutable + 5 immutable memtables), so this scales to roughly 6 fewer allocs per rollup miss. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Halves the per-memtable iterator construction allocation count by embedding the inner
IteratorinsideUniIteratorinstead of holding a*Iterator. PreviouslyNewUniIteratorallocated twice: once for the innerIterator(viaNewIterator) and once for theUniIteratorwrapper. Embedding by value collapses these into a single heap allocation.Extracts the shared
(*Iterator).inithelper so future setup added inNewIteratorapplies uniformly toUniIterator's embedded construction path.Motivation
In dgraph's posting list rollup, ~6
UniIterators are constructed per cache miss (1 mutable + 5 immutable memtables). This scales to roughly 6 fewer allocs per rollup miss.Benchmark — BenchmarkRollupKeyIterator
Test plan
go test ./skl/...passesgo test ./...passes🤖 Generated with Claude Code